package com.lemei.cn.myokhttpbeen.ui.fragment;

import android.view.View;

import com.lemei.cn.myokhttpbeen.R;
import com.lemei.cn.myokhttpbeen.adpter.SubjectAdpter;
import com.lemei.cn.myokhttpbeen.been.SubjectItemBeen;
import com.lemei.cn.myokhttpbeen.cachemanger.CacheManger;
import com.lemei.cn.myokhttpbeen.pullrefresh.PullToRefreshListView;
import com.lemei.cn.myokhttpbeen.utils.Uris;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 赵航 on 2017/6/11.
 */

public class SubjectFragment extends BeasicFragment {
    @Bind(R.id.lv_home_list_layout)
    PullToRefreshListView lvHomeListLayout;
    private List<SubjectItemBeen> mShownItems = new ArrayList();

    @Override
    protected Object requestNetData() {

        List<SubjectItemBeen> itemBeen= CacheManger.getInstance().getListData(Uris.SUBJECTURI, SubjectItemBeen.class);

        mShownItems.addAll(itemBeen);

        return itemBeen;
    }

    @Override
    public View creatSuccessView() {
        View view = View.inflate(getContext(), R.layout.home_show_layout, null);
        ButterKnife.bind(SubjectFragment.this,view);
        SubjectAdpter subjectAdpter = new SubjectAdpter(mShownItems);
        lvHomeListLayout.getRefreshableView().setAdapter(subjectAdpter);
//        设置当前上拉加载更多是否可用
        lvHomeListLayout.setPullLoadEnabled(true);
//        设置当前下拉刷新是否可用
        lvHomeListLayout.setPullRefreshEnabled(true);
//        滑动到底部是否自动加载更多数据
     //   lvHomeListLayout.setScrollLoadEnabled(true);

        return view;
    }
}
